package com.a2.appa3.util;

import android.support.annotation.NonNull;
import android.util.Log;

import com.a2.appa3.global.Constants;

/**
 * 打印工具类
 */
public class SYSOUtils {
    private static final boolean PRINT = Constants.TEST;//开启打印标记
    private static final String TAG = "MyLog";//打印标签

    private SYSOUtils() {
    }

    public static void errLog(String exceptionInfo, Throwable throwable) {
        if (!PRINT) return;

        StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[4];
        Log.e(TAG, ">----------------------------------------------------------------------------------------------------------------------------\n"
                + exceptionInfo + "\n"
                + stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + "@Line:" + stackTraceElement.getLineNumber());
        throwable.printStackTrace();
        Log.e(TAG, "\n<============================================================================================================================");

    }

    public static void tagLog(String tag, @NonNull Object... str) {
        if (!PRINT || str == null) return;
        for (Object obj : str) {
            if (obj == null) {
                Log.w(TAG, "null");
                continue;
            }
            Log.d(tag, obj.toString());
        }
    }

    public static void sOut(@NonNull Object... str) {
        if (!PRINT || str == null) return;
        StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[3];
        Log.e(TAG, ">----------------------------------------------------------------------------------------------------------------------------\n"
                + stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + "@Line:" + stackTraceElement.getLineNumber());
        for (Object obj : str) {
            if (obj == null) {
                Log.w(TAG, "null");
                continue;
            }
            Log.w(TAG, obj.toString());
        }
        Log.e(TAG, "\n<============================================================================================================================");
    }

    public static void sOut_(@NonNull Object... str) {
        if (!PRINT || str == null) return;
        StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[3];
        Log.e(TAG, ">++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
                + stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + "@Line:" + stackTraceElement.getLineNumber());
        for (Object obj : str) {
            if (obj == null) {
                Log.w(TAG, "null");
                continue;
            }
            Log.w(TAG, obj.toString());
        }
        Log.e(TAG, "\n<****************************************************************************************************************************");
    }

    public static void simple(@NonNull Object... str) {
        if (!PRINT || str == null) return;
        for (Object obj : str) {
            if (obj == null) {
                Log.w(TAG, "null");
                continue;
            }
            Log.w(TAG, obj.toString());
        }
    }
}
